package wang.aweb.childcar;

import cn.felord.payment.autoconfigure.EnableMobilePay;
import org.mybatis.spring.annotation.MapperScan;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.CommandLineRunner;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cache.annotation.EnableCaching;
import springfox.documentation.swagger2.annotations.EnableSwagger2;
import wang.aweb.childcar.tcpserver.NettyServer;
import wang.aweb.childcar.websocketserver.WebSocketServer;

import java.net.InetSocketAddress;

@SpringBootApplication
@MapperScan(basePackages = "wang.aweb.childcar.model.dao")
@EnableSwagger2
@EnableCaching
@EnableMobilePay

public class ChildCarApplication implements CommandLineRunner {
    @Value("${netty.port}")
    private int nettyPort;
    @Value("${netty.url}")
    private String nettyUrl;
    @Value("${websocket.port}")
    private int webSocketPort;
    @Value("${websocket.url}")
    private String webSocketUrl;
    @Autowired
    private WebSocketServer webSocketServer;
    @Autowired
    private NettyServer server;
    public static void main(String[] args) {
        SpringApplication.run(ChildCarApplication.class, args);
    }
    public void run(String... args) throws Exception{
        InetSocketAddress address=new InetSocketAddress(nettyUrl,nettyPort);
        //System.out.println("run .... . ... "+nettyUrl);
        server.start(address);
        InetSocketAddress webSocketAddress=new InetSocketAddress(webSocketUrl,webSocketPort);
        //System.out.println("run .... . ..."+webSocketUrl);
        webSocketServer.start(webSocketAddress);

    }

}
